package com.kele.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * @Version 2019
 * @Author:kele
 * @Date:2021/6/6
 * @Content:
 * @Description：
 */
public class MyInvocationHandler implements InvocationHandler {

    //传入委托对象
    private Object object=null;

    //返回代理对象
    public Object bind(Object object){
        this.object=object;
        return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),this);


    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //实现业务代码和非业务代码解耦合
        System.out.println(method.getName()+"⽅法的参数是"+
                Arrays.toString(args));
        Object result = method.invoke(this.object,args);
        System.out.println(method.getName()+"⽅法的结果是"+ result);
        return result;
    }
}
